<?php
namespace app\web\model;

use app\lib\model\Price;
/**
 * @package app\basic\model
 */
class User extends Base 
{

    protected function setCityAttr($v,$data)
    {
        if($v == '市辖区' || $v == '县') return $data['province'];
        return $v;
    }
    protected function getCreateTimeAttr($v)
    {
        return date('Y-m-d',$v);
    }

    public function getWithdrawalBalanceAttr($v,$data)
    {
        $a = UserBalance::where(['user_id'=>$data['id'],'status'=>0,'balance_type'=>4])->sum('change_balance');
        return Price::pricecalc($v,'+',$a);
    }

    
    /**
     * 生成邀请码
     * [getInvitationCode description]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public static function getInvitationCode($id)
    {
        $lent = strlen($id);
        return str_pad($id,$lent < 6 ? 6 : $lent,'0',STR_PAD_LEFT);
    }
}
